#include "type.h"

void main(int argc, char* argv[])
{
	do_write(2, "*****************************\n\r", 31);
	do_write(2, "*       JRR Cp Program      *\n\r", 31);
	do_write(2, "*****************************\n\r", 31);
	
	if (argc == 3)
	{
		int fd1, fd2, bytesRead;
		char buf[1024];
		
		do_creat(argv[2]);
		fd1 = open(argv[1], READ);
		fd2 = open(argv[2], WRITE);
		
		if ((fd1 > -1) && (fd2 > -1))
		{
			printf("Copying \"%s\" to \"%s\"\n", argv[1], argv[2]);
			do
			{
				bytesRead = do_read(fd1, buf, 1024);
				do_write(fd2, buf, bytesRead);
			} while (bytesRead == 1024);
			
			do_close(fd1);
			do_close(fd2);
		}
		else
		{
			printf("Bad filename!\n");
		}
	}
	else
	{
		printf("Usage: cp f1 f2\n");
		return;
	}
}
